// 
//  Copyright (C) 2004-2006  Autodesk, Inc.
//  
//  This library is free software; you can redistribute it and/or
//  modify it under the terms of version 2.1 of the GNU Lesser
//  General Public License as published by the Free Software Foundation.
//  
//  This library is distributed in the hope that it will be useful,
//  but WITHOUT ANY WARRANTY; without even the implied warranty of
//  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
//  Lesser General Public License for more details.
//  
//  You should have received a copy of the GNU Lesser General Public
//  License along with this library; if not, write to the Free Software
//  Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
#ifndef STDAFX_H
#define STDAFX_H

#include <wchar.h>
#include <ogrsf_frmts.h>
#include <ogr_attrind.h>
#include <mitab_ogr_driver.h>
#include <mitab.h>

#include "MapInfo.h"
#include "../Message/Inc/MapInfoMessage.h"

#ifdef _DEBUG
    #ifdef _WIN32
#ifndef ASSERT
        #include <crtdbg.h>
        #define ASSERT  _ASSERT
#endif
    #else
    /// linux doesn't seem to have a standard assert mechanism?
        #define _ASSERT(x)
        #define ASSERT(x)
    #endif
#else
    /// no assertions in release mode
#ifndef _ASSERT
    #define _ASSERT(x)
#endif
#ifndef ASSERT
    #define ASSERT(x)
#endif
#endif

// the default message catalog filename
extern char *fdoodbc_cat;

inline FdoString* NlsMsgGetMain(int msg_num, const char* default_msg, ...)
{
    va_list varargs;
    va_start(varargs, default_msg);
    FdoString* ret = FdoException::NLSGetMessage (msg_num, default_msg, fdoodbc_cat, varargs);
    va_end(varargs);

    return ret;
}

inline FdoString* NlsMsgGetMain(int msg_num, const char* default_msg, const char* file, int line, ...)
{
    va_list varargs;
    va_start(varargs, line);
    FdoString* ret = FdoException::NLSGetMessage (msg_num, default_msg, file, line, fdoodbc_cat, varargs);
    va_end(varargs);

    return ret;
}

//TODO: usage of wcstombs/mbstowcs is incorrect in most cases
#define A2W(x) \
    size_t len##x = strlen(x)*4+4; \
    wchar_t* w##x = (wchar_t*)alloca(len##x); \
    mbstowcs(w##x, x, len##x);
    
#define W2A(x) \
    size_t len##x = wcslen(x)*4+1; \
    char* mb##x = (char*)alloca(len##x); \
    wcstombs(mb##x, x, len##x);

#endif //STDAFX_H

